#include "../../lv_examples.h"
#include "board.h"
#if LV_BUILD_EXAMPLES
#if LV_USE_FREETYPE

/**
 * Load a font with FreeType
 */

    char dd1[50] = "";
    char dd2[50] = "";
    char dd3[50] = "";
    char dd4[50] = "";
    char dd5[50] = "";
    char dd6[50] = "";

    char sj[15];//时间
    char zz[50];//正在就诊

    char gh[100] = "过号:";

lv_obj_t * label;
lv_obj_t * labelzc;
lv_obj_t * label1;
lv_obj_t * label2;
lv_obj_t * labeldd1;
lv_obj_t * labeldd2;
lv_obj_t * labeldd3;
lv_obj_t * labeldd4;
lv_obj_t * labeldd5;
lv_obj_t * labeldd6;

lv_obj_t * labelgh;

pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;

void *set_test(void *arg)
{
    while(1)
    {
        usleep(1000*1000);
        pthread_mutex_lock( &m );
        lv_label_set_text(label1, sj);
        lv_label_set_text(label2, zz);
        lv_label_set_text(labeldd1, dd1);
        lv_label_set_text(labeldd2, dd2);
        lv_label_set_text(labeldd3, dd3);
        lv_label_set_text(labeldd4, dd4);
        lv_label_set_text(labeldd5, dd5); 
        lv_label_set_text(labeldd6, dd6);    
        pthread_mutex_unlock( &m );
    }
}


lv_coord_t xgh;
lv_coord_t ygh = 440;
void *gh_test(void *arg)
{
    while(1)
    {
        usleep(100*1000);
        
        if(strlen(gh) != 0)
        for(xgh = 800; xgh >= -200; xgh = xgh-2)
        {
            usleep(200*1000);
            lv_label_set_text(labelgh, gh);             
            lv_obj_set_pos(labelgh, xgh, ygh); 
        }
    }
}

void lv_example_freetype_1(void)
{
    pthread_t f;
    pthread_create(&f, NULL, set_test, NULL);


    // printf("%dn\n",__LINE__);

    /*Create a font*/
    static lv_ft_info_t info24;
    /*FreeType uses C standard file system, so no driver letter is required.*/
    info24.name = "./simfang.ttf";
    info24.weight = 24;
    info24.style = FT_FONT_STYLE_NORMAL;
    info24.mem = NULL;
    if(!lv_ft_font_init(&info24)) {
        LV_LOG_ERROR("create failed.");
    }

    // printf("%dn\n",__LINE__);

    /*Create a font*/
    static lv_ft_info_t info20;
    /*FreeType uses C standard file system, so no driver letter is required.*/
    info20.name = "./simfang.ttf";
    info20.weight = 20;
    info20.style = FT_FONT_STYLE_NORMAL;
    info20.mem = NULL;
    if(!lv_ft_font_init(&info20)) {
        LV_LOG_ERROR("create failed.");
    }

    /*Create a font*/
    static lv_ft_info_t info32;
    /*FreeType uses C standard file system, so no driver letter is required.*/
    info32.name = "./simfang.ttf";
    info32.weight = 32;
    info32.style = FT_FONT_STYLE_NORMAL;
    info32.mem = NULL;
    if(!lv_ft_font_init(&info32)) {
        LV_LOG_ERROR("create failed.");
    }    

    /*Create style with the new font*/
    static lv_style_t style24;
    lv_style_init(&style24);
    lv_style_set_text_font(&style24, info24.font);
    lv_style_set_text_align(&style24, LV_TEXT_ALIGN_CENTER);

    /*Create style with the new font*/
    static lv_style_t style20;
    lv_style_init(&style20);
    lv_style_set_text_font(&style20, info20.font);
    lv_style_set_text_align(&style20, LV_TEXT_ALIGN_CENTER);  

    /*Create style with the new font*/
    static lv_style_t style32;
    lv_style_init(&style32);
    lv_style_set_text_font(&style32, info32.font);
    lv_style_set_text_align(&style32, LV_TEXT_ALIGN_CENTER);       


////过号部分

    labelgh = lv_label_create(lv_scr_act());
    lv_obj_add_style(labelgh, &style24, 0);
    // lv_label_set_text(labelgh, gh);

    // xgh = 800;
    // ygh = 440;
    // lv_obj_set_pos(labelgh, xgh, ygh); 

    pthread_t g;
    pthread_create(&g, NULL, gh_test, NULL);


////医生部分
    /*Create a label with the new style*/
    label = lv_label_create(lv_scr_act());
    lv_obj_add_style(label, &style24, 0);
    lv_label_set_text(label, "李医师");
    // lv_obj_center(label);

    lv_coord_t x1 = 140;
    lv_coord_t y1 = 326;
    lv_obj_set_pos(label, x1, y1);

    labelzc = lv_label_create(lv_scr_act());
    lv_obj_add_style(labelzc, &style24, 0);
    lv_label_set_text(labelzc, "副主任医师");

    lv_coord_t xzc = 100;
    lv_coord_t yzc = 385;
    lv_obj_set_pos(labelzc, xzc, yzc);    

////时间部分
    // strcpy(sj, "2024/9/19");

    label1 = lv_label_create(lv_scr_act());
    lv_obj_add_style(label1, &style20, 0);
    // lv_label_set_text(label1, sj);    

    lv_coord_t x2 = 605;
    lv_coord_t y2 = 12;
    lv_obj_set_pos(label1, x2, y2); 

 ////正在就诊部分
    // strcpy(zz, "王答辩");
 
    label2 = lv_label_create(lv_scr_act());
    lv_obj_add_style(label2, &style32, 0);
    // lv_label_set_text(label2, zz);    

    lv_coord_t x3 = 520;
    lv_coord_t y3 = 80;
    lv_obj_set_pos(label2, x3, y3); 


////等待就诊列表部分
////
    // strcpy(dd1, "王大大");

    labeldd1 = lv_label_create(lv_scr_act());
    lv_obj_add_style(labeldd1, &style24, 0);
    // lv_label_set_text(labeldd1, dd1);    

    lv_coord_t xdd1 = 360;
    lv_coord_t ydd1 = 250;
    lv_obj_set_pos(labeldd1, xdd1, ydd1); 

////    
    // strcpy(dd2, "王小二");
    labeldd2 = lv_label_create(lv_scr_act());
    lv_obj_add_style(labeldd2, &style24, 0);
    // lv_label_set_text(labeldd2, dd2);    

    lv_coord_t xdd2 = 360;
    lv_coord_t ydd2 = 300;
    lv_obj_set_pos(labeldd2, xdd2, ydd2); 

////
    // strcpy(dd3, "王小三");
    labeldd3 = lv_label_create(lv_scr_act());
    lv_obj_add_style(labeldd3, &style24, 0);
    // lv_label_set_text(labeldd3, dd3);    

    lv_coord_t xdd3 = 360;
    lv_coord_t ydd3 = 350;
    lv_obj_set_pos(labeldd3, xdd3, ydd3);     

////
    // strcpy(dd4, "王小四");
    labeldd4 = lv_label_create(lv_scr_act());
    lv_obj_add_style(labeldd4, &style24, 0);
    // lv_label_set_text(labeldd4, dd4);    

    lv_coord_t xdd4 = 570;
    lv_coord_t ydd4 = 250;
    lv_obj_set_pos(labeldd4, xdd4, ydd4); 

////    
    // strcpy(dd5, "王小五");
    labeldd5 = lv_label_create(lv_scr_act());
    lv_obj_add_style(labeldd5, &style24, 0);
    // lv_label_set_text(labeldd5, dd5);    

    lv_coord_t xdd5 = 570;
    lv_coord_t ydd5 = 300;
    lv_obj_set_pos(labeldd5, xdd5, ydd5); 

////
    // strcpy(dd6, "王小六");
    labeldd6 = lv_label_create(lv_scr_act());
    lv_obj_add_style(labeldd6, &style24, 0);
    // lv_label_set_text(labeldd6, dd6);    

    lv_coord_t xdd6 = 570;
    lv_coord_t ydd6 = 350;
    lv_obj_set_pos(labeldd6, xdd6, ydd6);      


}
#else

void lv_example_freetype_1(void)
{
    /*TODO
     *fallback for online examples*/

    lv_obj_t * label = lv_label_create(lv_scr_act());
    lv_label_set_text(label, "FreeType is not installed");
    lv_obj_center(label);
}

#endif
#endif

